package com.sskj.mine.presenter;

import com.alibaba.android.arouter.launcher.ARouter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.enums.CodeTypeEnum;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.router.provider.SendSmsProvider;
import com.sskj.lib.util.CommonUtil;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.BindMobileActivity;


/**
 * @author Hey
 * Create at  2019/05/01
 */
public class BindMobilePresenter extends BasePresenter<BindMobileActivity> {

    public void bindMobile(String mobile, String code, String tpwd, String areaCode) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_MOBILE_OR_EMAIL)
                .params("account", mobile) // 手机号
                .params("code", code)  // 验证码
                .params("dealPswd", tpwd, true)
                .params("areaCode", areaCode.replace("+", ""))
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getStatus() == HttpConfig.OK) {
                            mView.finish();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                    }
                });
    }


    public void updateMobile(String mobile, String id, String tpwd) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.UPDATE_MOBILE_OR_EMAIL)
                .params("account", mobile) // 手机号
                .params("id", id) // 手机号
//                .params("code", code)  // 验证码
                .params("tradePswd", tpwd, true)
//                .params("areaCode", areaCode.replace("+",""))
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getStatus() == HttpConfig.OK) {
                            mView.finish();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                    }
                });
    }

    public void sendCode(String mobile, String areaCode) {
        SendSmsProvider sendSmsProvider = ARouter.getInstance().navigation(SendSmsProvider.class);
        sendSmsProvider.send(this, mobile, areaCode, CodeTypeEnum.STATUS_3, null, new SendSmsProvider.OnSend() {
            @Override
            public void onSuccess() {
                mView.onAuthCodeSuccess();

            }

            @Override
            public void onFail() {
                mView.onAuthCodeFail();
            }
        });

    }


}
